package com.tshopping.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @name: FileUploader
 * @description: 上传文件工具类
 * @author: Jackeys
 * @date: 2021-01-04 15:04
 */
public class FileUploader {
    public static boolean upload(String directoryPath,MultipartFile file){
        File directory = new File(directoryPath);
        if (!directory.exists()) {
            directory.mkdirs();
        }
        try {
            file.transferTo(new File(directoryPath+new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").format(new Date())));
        }catch (IOException e){
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
